<?php

defined('_JEXEC') or die();
 
class TableCampaigns extends JTable {
	
        // Fields
	var  $id = null;
	var  $title = '';
	var  $alias = '';
	var  $description = '';
	var  $image = '';
	var  $params = '';
	var  $published = 0;
	var  $access = '';
	var  $created_time = '0000-00-00 00:00:00';
	var  $created_by = 0;
	var  $modified_time = '0000-00-00 00:00:00';
	var  $modified_by = 0;
	var  $checked_out_time = '0000-00-00 00:00:00';
	var  $checked_out = 0;

	/**
	 * Constructor
	 *
	 * @param object Database connector object
	 * @since 1.0
	 */
	function __construct( &$db )
	{
		parent::__construct( '#__letterman_campaigns', 'id', $db );
	}

	/**
	 * Constructor
	 *
	 * @param object Database connector
	 * @since 1.0
	 */
	function TableRokdownloads(& $db) {
		parent :: __construct('#__letterman_campaigns', 'id', $db);
	}

	/**
	* Overloaded bind function
	*
	* @acces public
	* @param array $hash named array
	* @return null|string	null is operation was satisfactory, otherwise returns an error
	* @see JTable:bind
	* @since 1.5
	*/

	function bind($from, $ignore = '') {
		$fromArray    = is_array( $from );
        $fromObject    = is_object( $from );


		if (!$fromArray && !$fromObject)
        {
            $this->setError( JText::sprintf('ERROR.BIND_FAILED', get_class( $this )));
            $this->setErrorNum(20);
            return false;
        }
        if ($fromArray) {
        	if (key_exists('params', $from) && is_array($from['params'])) {
				$registry = new JRegistry();
				$registry->loadArray($from['params']);
				$from['params'] = $registry->toString();
			}
        }
        else if ($fromObject) {
			if (is_array($from->params)) {
				$registry = new JRegistry();
				$registry->loadArray($from->params);
				$from->params = $registry->toString();
			}
        }

		$retobject = parent :: bind($from, $ignore);

		if ($this->path != '') {
			$this->_missing = !(file_exists(COM_ROKDOWNLOADS_BASE.DS.$this->path));
			if (!$this->_missing) $this->_readable = is_readable(COM_ROKDOWNLOADS_BASE.$this->path);
		}
		
		return $retobject;
	}

	/**
	 * Overloaded check method to ensure data integrity
	 *
	 * @access public
	 * @return boolean True on success
	 * @since 1.0
	 */
	function check() {
		/** check for valid file name */
		if (trim($this->name) == '') {
			$this->setError(JText::_('ERROR.DOWNLOAD_ITEM_MUST_HAVE_NAME'));
			return false;
		}
		// name sure there is a displayname
		if (trim($this->displayname) == '') {
			$this->displayname = $this->name;
		}

		return true;
	}

	function load($oid = null) {
		$ret =& parent :: load($oid);
		if ($ret) {
			$this->_loadedfromdb = true;

		}
		return $ret;
	}

}
?>

